//
//  MainHeaderview.m
//  Bettle
//
//  Created by panhongliu on 2017/1/5.
//  Copyright © 2017年 panhongliu. All rights reserved.
//

#import "MainHeaderview.h"
#import "MainHeaderCollectionViewCell.h"
@implementation MainHeaderview


- (void)awakeFromNib {
    [super awakeFromNib];
    NSLog(@"ssd");
    self.backgroundColor=[UIColor redColor];
    flowLayout= [[UICollectionViewFlowLayout alloc]init];
    
    flowLayout.scrollDirection =UICollectionViewScrollDirectionVertical;
    flowLayout.minimumLineSpacing = 0;
    
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height) collectionViewLayout:flowLayout];
    
    //    flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-30)/2, (SCREEN_WIDTH-30)/2+47);
    
    UINib *nib = [UINib nibWithNibName:@"MainHeaderCollectionViewCell"
                                bundle: [NSBundle mainBundle]];
    [self.collectionView registerNib:nib forCellWithReuseIdentifier:@"MainHeaderCollectionViewCell"];
    self.collectionView.backgroundColor=[UIColor whiteColor];
    
    
    flowLayout.scrollDirection =UICollectionViewScrollDirectionHorizontal;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self addSubview:self.collectionView];

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{
    return 5;
    
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
       return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    WeakSelf(weakSelf, self);
        MainHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MainHeaderCollectionViewCell" forIndexPath:indexPath];
    
    return cell;
    
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
           return CGSizeMake(self.width-80,self.height);
        
  
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
        return UIEdgeInsetsMake(0, 0,0, 20);
        
   
    
}


@end
